<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class YewuController extends HomeController {

    //微信展示
	public function index($id){
		$ywlb   = D('Ywlb');
        //获取权限
        $code   = I('code');//微信接口CODE值用作查用户OPEN值的
		$weixin = new WeixinController;
		$openid = $weixin->wyaccess_token($code);
		$yz['status']     =  array('eq',1);
		$yz['openid']     =  array('eq',$openid['openid']);
		$user   = D('Member')->where($yz)->field('jb_id')->find();
		$group  = $user['jb_id']; 
		$this->assign('group',$group);
		//提交数据
		if(IS_POST){
			$yewu  = D('Yewu');
			$data  = $yewu->create();
 			$res   = $yewu->where(array('id'=>$data['id']))->save();
 			if($result !== false){
 				//信息发送提醒
/* 		        if($data['ywstate'] == 33){//判断业务系统是否等于33（待确定）
                        if($data['xsjd']){  //判断线上经理
                            $this->xsfendan($data['id']);  //发送微信提醒到线上门市
                        }
                    }
                    if($data['ywstate'] == 63){//判断业务系统是否等于63（确认意向）
                        if($data['xxjd']){  //判断下线经理
                            $this->xxfendan($data['id']); 
                       
                        }else{
                            $this->fenpei($data['id'],3);  
                        }
                        
                    }
                    //判断业务（无效、未到店、流失）后发送微信提醒，提醒线上客服
                if($data['ywstate'] == 64 || $data['ywstate'] == 65 || $data['ywstate'] == 66){
                        $this->xsjdtixing($data['id']); 
                } */
 				$this->success('订单更改成功!',U('Wxbb/cj'),1);
 			}else{
 				$this->error('订单更改失败!');
 			}
		}else{
	        //查询业务状态列表
	        $state  = $ywlb->yw($group);
	        $this->assign('state',$state);

	        //查询渠道
	        $qudao  = $ywlb->qd();
	        $this->assign('qudao',$qudao);
	        //查询类别
	        $liebei = $ywlb->lb();
	        $this->assign('liebei',$liebei);

	        //客服
	        $kefu = kefu($group);
	        $this->assign('kefu',$kefu);


	        //线下
	        $xianxia = xianxia($group);
	        $this->assign('xianxia',$xianxia);

	        //线下
	        $xianshang = xianshang($group);
	        $this->assign('xianshang',$xianshang);
			
			if(!$user){
				$this->error("没有权限！");
			}
			//判断是否能找到OPENID
			$data = $this->shuju($id,$openid);
	        $this->assign('data',$data);
		}

		$this->meta_title = '业务管理系统';
		$this->display();
	}

}